import { ConfigEnv, defineConfig, UserConfig } from 'vite'
import commonViteConfig from "./vite.config.common"
import testViteConfig from "./vite.config.test"
import productionViteConfig from "./vite.config.production"
import developmentViteConfig from "./vite.config.development"

// https://vite.dev/config/
export default defineConfig((configEnv): UserConfig => {
  return Object.assign(
    {},
    commonViteConfig(configEnv),
    viteConfigResolver[configEnv.mode] ?
      viteConfigResolver[configEnv.mode](configEnv) :
      {}
  )
})

/**
 * 生产/测试/开发环境的vite
 */
const viteConfigResolver: Record<string, (configEnv: ConfigEnv) => UserConfig> = {
  "production": (configEnv: ConfigEnv) => {
    return productionViteConfig
  },
  "test": (configEnv: ConfigEnv) => {
    return testViteConfig
  },
  "development": (configEnv: ConfigEnv) => {
    return developmentViteConfig(configEnv)
  }
}